package com.mldong.modules.sys.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mldong.base.CommonPage;
import com.mldong.base.CommonResult;
import com.mldong.base.IdParam;
import com.mldong.base.IdsParam;
import com.mldong.modules.sys.dto.TaskExecutionQueuePageParam;
import com.mldong.modules.sys.dto.TaskExecutionQueueParam;
import com.mldong.modules.sys.service.TaskExecutionQueueService;
import com.mldong.modules.sys.vo.TaskExecutionQueueVO;
import com.mldong.validation.Groups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 待执行任务队列 前端控制器
    * </p>
*
* @author mldong
* @since 2025-10-12
*/
@RestController
@Api(tags = "待执行任务队列管理")
@RequiredArgsConstructor
public class TaskExecutionQueueController {
    private final TaskExecutionQueueService taskExecutionQueueService;
    /**
     * 添加待执行任务队列
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionQueue/save")
    @ApiOperation(value = "添加待执行任务队列")
    @SaCheckPermission("sys:taskExecutionQueue:save")
    public CommonResult<?> save(@RequestBody @Validated({Groups.Save.class}) TaskExecutionQueueParam param) {
        taskExecutionQueueService.save(param);
        return CommonResult.ok();
    }
    /**
     * 删除待执行任务队列
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionQueue/remove")
    @ApiOperation(value = "删除待执行任务队列")
    @SaCheckPermission("sys:taskExecutionQueue:remove")
    public CommonResult<?> remove(@RequestBody IdsParam param) {
        taskExecutionQueueService.removeBatchByIds(param.getIds());
        return CommonResult.ok();
    }
    /**
     * 修改待执行任务队列
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionQueue/update")
    @ApiOperation(value = "修改待执行任务队列")
    @SaCheckPermission("sys:taskExecutionQueue:update")
    public CommonResult<?> update(@RequestBody @Validated({Groups.Update.class}) TaskExecutionQueueParam param) {
        taskExecutionQueueService.update(param);
        return CommonResult.ok();
    }
    /**
     * 查询单个待执行任务队列
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionQueue/detail")
    @ApiOperation(value = "查询单个待执行任务队列")
    @SaCheckPermission("sys:taskExecutionQueue:detail")
    public CommonResult<TaskExecutionQueueVO> detail(@RequestBody IdParam param) {
        TaskExecutionQueueVO taskExecutionQueue = taskExecutionQueueService.findById(param.getId());
        return CommonResult.data(taskExecutionQueue);
    }
    /**
     *分页查询待执行任务队列列表
     * @param param
     * @return
     */
    @PostMapping("/sys/taskExecutionQueue/page")
    @ApiOperation(value = "分页查询待执行任务队列列表")
    @SaCheckPermission("sys:taskExecutionQueue:page")
    public CommonResult<CommonPage<TaskExecutionQueueVO>> page(@RequestBody TaskExecutionQueuePageParam param) {
        return CommonResult.data(taskExecutionQueueService.page(param));
    }
}
